package com.rd.teacher.jichao.day15;

public class TestDeadLock {

    Object A = new Object();
    Object B = new Object();

    public void AtoB() {
        synchronized (A) {
            synchronized (B) {
                System.out.println(Thread.currentThread().getName()
                        + " A -> B");
            }
        }
    }

    public void BtoA() {
        synchronized (B) {
            synchronized (A) {
                System.out.println(Thread.currentThread().getName()
                        + " B -> A");
            }
        }
    }

    public static void main(String[] args) {
        TestDeadLock testDeadLock = new TestDeadLock();
        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    testDeadLock.AtoB();
                    testDeadLock.BtoA();
                }
            }).start();
        }
    }

}
